﻿#region Namespace References

using System;
using System.Collections.Generic;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.Core.Metadata
{
    public class SmartMetaDataStore
    {
        #region Constructors

        private SmartMetaDataStore()
        {
        }

        #endregion

        #region Public Static Properties

        public static SmartMetaDataStore GlobalInstance
        {
            get { return s_GlobalInstance; }
        }

        #endregion

        #region Public Instance Methods

        public SmartMetaEntity GetMetaEntity(Type entityType)
        {
            SmartMetaEntity retVal;
            String metaKey = GetMetaKey(entityType);
            if (!m_Store.TryGetValue(metaKey, out retVal))
            {
                retVal = new SmartMetaEntity(entityType);
                m_Store.Add(metaKey, retVal);
            }
            return retVal;
        }

        #endregion

        #region Private Instance Methods

        private string GetMetaKey(Type entityType)
        {
            return entityType.AssemblyQualifiedName;
        }

        #endregion

        #region Fields and Constants

        private static readonly SmartMetaDataStore s_GlobalInstance = new SmartMetaDataStore();

        private readonly Dictionary<String, SmartMetaEntity> m_Store = new Dictionary<string, SmartMetaEntity>();

        #endregion
    }
}